<template>
  <div class="app-container">
    <el-divider content-position="center">测试功能</el-divider>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="handleAdd">新增</el-button>
      </el-col>
      
    </el-row>
    <el-table v-loading="loading" :data="testList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="主键ID" align="center" prop="projectId" /> -->
    <el-table-column label="序号" type="index" width="50" align="center" prop="projectId" />      
    <el-table-column label="测试人员" align="center" prop="testName" />
    <el-table-column label="测试功能" align="center" prop="testMethod" />
    <el-table-column label="测试时间" align="center" prop="testDate" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" @click="handleUpdate(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    

    <!-- 添加或修改对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="testRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="测试人员" prop="testName">
          <el-input v-model="form.testName" placeholder="请输入测试人员" />
        </el-form-item>
        <el-form-item label="测试功能" prop="testMethod">
          <el-input v-model="form.testMethod" placeholder="请输入测试功能" />
        </el-form-item>
        <el-form-item label="车辆图片" prop="image">
          <image-upload v-model="form.image"/>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    
  

  </div>
</template>

<script setup name="test">

// 全局字典的方式,参考全局字典
const { proxy } = getCurrentInstance();
const testList = ref([
  {"testName":"满叔","testMethod":"上传功能","testDate":"2025-03-27 12:00:00","image":""}
]);


const open = ref(false);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const title = ref("");
const data = reactive({
  form: {}
});

const { form } = toRefs(data);



// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    testName: null,
    testMethod: null,
    testDate: null
  };
  proxy.resetForm("testRef");
}




// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.projectId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加项目管理";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  form.value = row;
  open.value = true;
}
/** 提交按钮 */
function submitForm() {
  proxy.$refs["testRef"].validate(valid => {
    console.log(valid);
    if (valid) {
      console.log(form.value);
      proxy.$modal.msgSuccess("修改成功");
    }
  });
}

</script>
